<template>
  <div class="book">
    <div class="head-search">
      <search @onSubmit="onSearch">
        <el-form-item>
          <el-input placeholder="请输入内容" clearable v-model="searchData.val" size="small" class="input-with-select">
            <el-select v-model="searchData.select" clearable slot="prepend" placeholder="请选择">
              <el-option v-for="(item, index) in searchOptions"
                         :key="index"
                         :label="item.mdName"
                         :value="item.mdCode"></el-option>
            </el-select>
          </el-input>
        </el-form-item>
      </search>
      <el-button @click="handleDrawer('search')" class="btn" type="primary" size="small">高级检索</el-button>
    </div>
    <section class="fun-btn">
      <el-button @click="handleDrawer('add')"
                 type="primary"
                 size="small"
                 v-if="btnJurisdiction['add']"
                 icon="el-icon-circle-plus-outline">新增
      </el-button>

      <el-button @click="handleInOut('0')"
                 style="margin-left: 10px"
                 type="primary"
                 icon="el-icon-upload"
                 v-if="btnJurisdiction['imp']"
                 size="small">导入
      </el-button>
      <el-button @click="handleInOut('1')"
                 icon="el-icon-download"
                 type="primary"
                 v-if="btnJurisdiction['exp']"
                 size="small">导出
      </el-button>
      <el-button @click="handleInOut('2')"
                 type="primary"
                 icon="el-icon-s-data"
                 size="small">报表
      </el-button>
      <el-button @click="handleDrawer('arrange')"
                 type="primary"
                 v-if="btnJurisdiction['up']"
                 size="small">整理
      </el-button>
      <el-button type="primary"
                 size="small"
                 v-if="btnJurisdiction['filing']"
                 @click="handleFile">归档</el-button>

      <el-button @click="handleDrawer('batchEdit')"
                 style="margin-left: 10px"
                 type="primary"
                 v-if="btnJurisdiction['mod'] || btnJurisdiction['rep']"
                 size="small">修改/替换
      </el-button>
      <!--<el-button class="btn" type="primary" size="small">挂接原文</el-button>-->
      <el-button @click="handleDrawer('set')" type="primary" size="small">设置</el-button>
      <el-button @click="handleDel"
                 type="danger"
                 plain
                 v-if="btnJurisdiction['delete']"
                 size="small">删除</el-button>
    </section>

    <section class="list-box">
      <el-table
        :data="tableData"
        border
        ref="table"
        v-loading="tableLoading"
        height="calc(100vh - 252px)"
        @row-dblclick="handlerRowDblClick"
        @selection-change="handleSelectionChange"
        @sort-change="handleSortChange"
        class="table">
        <el-table-column
          align="center"
          type="selection"
          fixed="left"
          width="60">
        </el-table-column>
        <el-table-column
          align="center"
          type="index"
          label="序号"
          width="60">
        </el-table-column>

        <el-table-column
          v-for="(item, index) in headTableList"
          :key="index"
          :sortable="item.sort"
          show-overflow-tooltip
          :prop="item.mdCode"
          :label="item.mdName"
          :min-width="item.width"
          :align="item.mdCode === 'tm' ? 'left' : 'center'"
        >
        </el-table-column>

        <el-table-column
          fixed="right"
          label="操作"
          align="center"
          width="120">
          <template slot-scope="scope">
            <!--            <el-button @click="handleDrawer('edit', scope.row)" type="text">查看</el-button>-->
            <el-button icon="el-icon-edit"
                       @click="handleDrawer('edit', scope.row)" type="text">编辑
            </el-button>
            <!--            <el-button type="text">原文</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-if="listTable"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNo"
        :page-sizes="[20, 40, 60, 80]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listTable ? Number(listTable.total) : 0">
      </el-pagination>
    </section>

    <el-drawer
      :title="setDrawer.title"
      :size="setDrawer.size"
      :direction="setDrawer.direction"
      :visible.sync="drawer"
      :destroy-on-close="true"
    ><!--:with-header="false"-->
      <add-electronics v-if="setDrawer.type === 'add' || setDrawer.type === 'edit'"
                       :formOptions="formOptions"
                       :idTable="idTable"
                       :rowData="rowData"
                       :idCategory="idCategory"
                       :type="type"
                       @handleAddSuccess="handleAddEditSuccess"></add-electronics>

      <arrange v-if="setDrawer.type === 'arrange'"
               :pdfSrc="pdfSrc"
               :idTable="idTable"
               :rowData="rowData"
               :fmtJson="fmtJson"
               :type="'simplify'"
               :page="page"
               :tableData="tableData"
               :allData="listTable"
               :idCategory="idCategory"
               :formOptions="arrangeFormOptions"
               @handlePrev="handlePrev"
               @handleNext="handleNext"
               @handleGetPdfSrc="handleGetPdfSrc"></arrange>
      <edit-replace
        :idTable="idTable"
        :tableSelected="tableSelected"
        v-if="setDrawer.type === 'batchEdit'"
        @handleSuccess="getList"></edit-replace>
      <set-up :idTable="idTable" @handleSuccess="handleSuccess" v-if="setDrawer.type === 'set'"></set-up>
      <!--高级检索-->
      <senior-search :idTable="idTable"
                     :idCategory="idCategory"
                     :qzDataSelect="qzDataSelect"
                     @handleSenior="handleSenior"
                     v-if="setDrawer.type === 'search'"></senior-search>
    </el-drawer>

    <el-dialog :title="dialogTitle"
               :width="dialogWidth"
               top="5vh"
               :destroy-on-close="true"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               :visible.sync="dialogVisible">
      <div class="import-content">
        <template-import v-if="dialogTitle === '导入'"></template-import>

        <template-export v-if="dialogTitle === '导出'"></template-export>

        <report-form :reportScope="reportScope"
                     @handlePreviewPrint="handlePreviewPrint"
                     :isSelect="tableSelected.length>0"
                     :isSearch="params.length>0"
                     :loading="previewPrintLoading"
                     v-if="dialogTitle === '报表'"></report-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Search from '../../../../../components/search/search'
import AddElectronics from '../component/drawer/addElectronics'
import TemplateImport from '../component/inOut/templateImport'
import TemplateExport from '../component/inOut/templateExport'
import Arrange from '../component/drawer/arrange'
import EditReplace from '../component/drawer/editReplace'
import SetUp from '../component/drawer/setUp'
import SeniorSearch from '../component/drawer/seniorSearch'
import { mapFields } from 'vuex-map-fields'
import { mapActions } from 'vuex'

import {
  delArchivesList,
  getPdfOriginal,
  requestFile, requestPrint,
  requestRange
} from '../../../../../api/electronicsFile/electronicsFile'
import { getQzDic } from '../../../../../api/quanzong/quanzong'
import { getObjectURL } from '../../../../../util/util'
import { getCategoryDicTypeName } from '../../../../../api/category/category'
import ReportForm from '../../../../../components/reportForm/reportForm'

export default {
  name: 'SimplifyBook', // 简化文书
  props: {
    idTable: {
      type: String
    },
    idCategory: {
      type: String
    }
  },
  components: {
    ReportForm,
    SeniorSearch,
    SetUp,
    EditReplace,
    Arrange,
    TemplateExport,
    TemplateImport,
    AddElectronics,
    Search
  },
  data () {
    return {
      drawer: false, // 新增
      dialogVisible: false, // 导入
      dialogTitle: '',
      dialogWidth: '80%',
      type: '',
      setDrawer: {
        title: '',
        size: '',
        direction: 'ltr'
      },
      searchData: {
        val: '', // 筛选
        select: '' // 筛选
      },
      tableSelected: [],
      page: {
        pageNo: 1,
        pageSize: 20
      },
      params: [], // 搜索的条件
      selectOption: [], // 搜索的下拉框
      qzDataSelect: [], // 全宗号下拉框
      pdfSrc: '', // 显示pdf数据
      rowData: {}, // 某一条目的数据
      reportScope: [], // 报表范围
      previewPrintLoading: false, // 报表loading
      dictTypeName: {},
      sortSet: {}, // 记录排序点击后状态
      sortCondition: [] // 排序条件传入
    }
  },
  mounted () {
    this.getSearch()
    this.getDicTypeNames()
    getQzDic({
      pageNo: 1,
      pageSize: 1000
    }).then(res => {
      this.qzDataSelect = res.data.data.list
    })
  },
  computed: {
    ...mapFields('electronicsFile/getHead', {
      sortRetrieved: 'sortRetrieved',
      headTable: 'retrieved',
      listTable: 'listRetrieved',
      tableLoading: 'loading'
    }),
    ...mapFields('electronicsFile/getSearch', {
      searchOptions: 'retrieved'
    }),
    ...mapFields('electronicsFile/setSearchCondition', {
      searchParams: 'retrieved'
    }),
    ...mapFields('profile/getCategoryType', {
      categoryTreeType: 'dzFile',
      zhengliForm: 'dzFileZl'
    }),
    ...mapFields('profile/profile', {
      userInfo: 'retrieved'
    }),
    ...mapFields('profile/getDh', {
      dhgz: 'retrieved'
    }),
    fmtJson () {
      // 获取档号格式
      let fmtJson = []
      if (this.dhgz) {
        fmtJson = JSON.parse(this.dhgz.fmtJson)
      }
      return fmtJson
    },
    btnJurisdiction () {
      const btnShow = {}
      if (this.userInfo) {
        this.userInfo.perms.map(item => {
          if (item.indexOf('dzwj') > -1) {
            btnShow[item.split(':')[2]] = true
          }
        })
      }
      return btnShow
    },
    headTableList () {
      return this.headTable ? this.headTable : []
    },
    tableData () {
      return this.listTable ? this.listTable.records : []
    },
    listIndex () {
      // 当前rowData的索引
      let indexNum = 0
      this.tableData.map((item, index) => {
        if (item.id === this.rowData.id) {
          indexNum = index
        }
      })
      return indexNum
    },
    formOptions () {
      let options = {
        mockBtn: false,
        emptyBtn: false,
        submitBtn: false,
        column: [
          {
            label: '全宗号',
            prop: 'qzh',
            span: 12,
            type: 'select',
            dicData: this.qzDataSelect,
            props: {
              label: 'fondsName',
              value: 'fondsNo'
            },
            slot: true
          },
          {
            label: '部门',
            prop: 'zldw',
            type: 'select',
            span: 12,
            props: {
              label: 'orgName',
              value: 'id'
            },
            rules: [{
              required: true,
              message: '请选择部门',
              trigger: 'blur'
            }]
          },
          {
            label: '文号',
            prop: 'wh',
            span: 24
          },
          {
            label: '责任者',
            prop: 'zrz',
            type: 'input',
            span: 24
          },
          {
            label: '题名',
            prop: 'tm',
            type: 'textarea',
            maxRows: 6,
            minRows: 4,
            maxlength: 500,
            showWordLimit: true,
            span: 24,
            rules: [{
              required: true,
              message: '请输入题名',
              trigger: 'blur'
            }]
          },
          {
            label: '成文日期',
            prop: 'cwrq',
            span: 12,
            maxlength: 8
          },
          {
            label: '页数',
            prop: 'ys',
            type: 'number',
            span: 12,
            minRows: 1,
            maxRows: 3000,
            row: true
          },
          {
            label: '抄送',
            prop: 'cs',
            span: 12
          },
          {
            label: '紧急程度',
            prop: 'jjcd',
            span: 12,
            type: 'select',
            dicData: []
          },
          {
            label: '抄送部门',
            span: 12,
            prop: 'ngbm'
          },
          {
            label: '主送',
            prop: 'zs',
            span: 12
          },
          {
            label: '备注',
            prop: 'bz',
            type: 'textarea',
            span: 24,
            maxRows: 6,
            minRows: 4,
            maxlength: 500,
            showWordLimit: true
          }
        ]
      }

      if (
        this.formType(this.categoryTreeType) &&
        this.categoryTreeType[this.formType(this.categoryTreeType)]
      ) {
        options = JSON.parse(
          JSON.stringify(this.categoryTreeType[this.formType(this.categoryTreeType)])
        )
      }

      this.setOptions(options)
      return options
    },
    arrangeFormOptions () {
      let options = {
        mockBtn: false,
        emptyBtn: false,
        submitBtn: false,
        column: [
          {
            label: '全宗号',
            prop: 'qzh',
            span: 12,
            type: 'select',
            dicData: this.qzDataSelect,
            props: {
              label: 'fondsName',
              value: 'fondsNo'
            },
            slot: true
          },
          {
            label: '部门',
            prop: 'zldw',
            type: 'select',
            span: 12,
            props: {
              label: 'orgName',
              value: 'id'
            },
            rules: [{
              required: true,
              message: '请选择部门',
              trigger: 'blur'
            }]
          },
          {
            label: '文号',
            prop: 'wh',
            span: 12
          },
          {
            label: '责任者',
            prop: 'zrz',
            type: 'input',
            span: 12
          },
          {
            label: '成文日期',
            prop: 'cwrq',
            span: 12,
            maxlength: 8
          },
          {
            label: '题名',
            prop: 'tm',
            type: 'textarea',
            maxRows: 6,
            minRows: 4,
            maxlength: 500,
            showWordLimit: true,
            span: 24,
            rules: [{
              required: true,
              message: '请输入题名',
              trigger: 'blur'
            }]
          },
          {
            label: '页数',
            prop: 'ys',
            type: 'number',
            span: 12,
            minRows: 1,
            maxRows: 3000,
            row: true
          },
          {
            label: '归档年度',
            prop: 'gdnd',
            span: 12
          },
          {
            label: '保管期限',
            prop: 'bgqx',
            span: 12,
            type: 'select',
            dicUrl: `/yuyi-config-boot/api/config/arcDictType/child?dictTypeName=${this.dictTypeName.bgqx}`,
            props: {
              label: 'dictLabel',
              value: 'dictValue'
            }
          },
          {
            label: '件号',
            prop: 'jh',
            span: 12
          },
          {
            label: '档号',
            prop: 'dh',
            span: 12,
            disabled: true
          },
          {
            label: '归档标识',
            prop: 'gdbs',
            span: 12,
            disabled: true,
            type: 'select',
            dicUrl: `/yuyi-config-boot/api/config/arcDictType/child?dictTypeName=${this.dictTypeName.gdbs}`,
            props: {
              label: 'dictLabel',
              value: 'dictValue'
            }
          },
          {
            label: '备注',
            prop: 'bz',
            type: 'textarea',
            span: 24,
            maxRows: 6,
            minRows: 4,
            maxlength: 500,
            showWordLimit: true
          }
        ]
      }

      if (
        this.formType(this.zhengliForm) &&
        this.zhengliForm[this.formType(this.zhengliForm)]
      ) {
        options = JSON.parse(
          JSON.stringify(this.zhengliForm[this.formType(this.zhengliForm)])
        )
      }

      this.setOptions(options)

      return options
    }
  },
  methods: {
    ...mapActions('electronicsFile/getHead', ['getTableList']),
    ...mapActions('electronicsFile/getSearch', ['getSearchOptions']),
    formType (jsonData) {
      let type = ''
      if (this.idCategory) {
        jsonData.category.map(item => {
          if (item.id === this.idCategory) {
            type = item.component
          }
        })
      }
      return type
    },
    setOptions (options) {
      return options.column.map(item => {
        if (item.prop === 'qzh') {
          item.dicData = this.qzDataSelect
        }
        if (item.prop === 'bgqx') {
          item.dicUrl = `/yuyi-config-boot/api/config/arcDictType/child?dictTypeName=${this.dictTypeName.bgqx}`
        }
        if (item.prop === 'mj') {
          item.dicUrl = `/yuyi-config-boot/api/config/arcDictType/child?dictTypeName=${this.dictTypeName.mj}`
        }
        if (item.prop === 'gdbs') {
          item.dicUrl = `/yuyi-config-boot/api/config/arcDictType/child?dictTypeName=${this.dictTypeName.gdbs}`
        }
      })
    },
    async getSearch () {
      await this.getSearchOptions(this.idTable)
      this.searchData.select = this.searchOptions[0].mdCode
      this.searchOptions.map(item => {
        if (item.mdCode === 'tm') {
          this.searchData.select = 'tm'
        }
      })
    },
    getDicTypeNames () {
      // 获取数据字典需要传入的参数
      getCategoryDicTypeName(this.idTable, 'bgqx').then(res => {
        this.$set(this.dictTypeName, 'bgqx', res.data.data.dictTypeName)
      })
      getCategoryDicTypeName(this.idTable, 'mj').then(res => {
        this.$set(this.dictTypeName, 'mj', res.data.data.dictTypeName)
      })
      getCategoryDicTypeName(this.idTable, 'gdbs').then(res => {
        this.$set(this.dictTypeName, 'gdbs', res.data.data.dictTypeName)
      })
    },
    getList () {
      // 获取
      const param = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
        params: this.searchParams.concat(this.params)
      }
      if (this.sortCondition.length > 0) {
        param.sorters = this.sortCondition
      }
      return this.getTableList({
        idTable: this.idTable,
        data: param
      })
    },
    handleAddEditSuccess () {
      this.drawer = false
      this.type = ''
      this.rowData = {}
      this.getList()
    },
    handleSizeChange (val) {
      // console.log(`每页 ${val} 条`)
      this.page.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      // console.log(`当前页: ${val}`)
      this.page.pageNo = val
      this.getList()
    },
    handleSuccess () {
      // 检索设置成功
      this.getList()
    },
    onSearch () {
      // 搜索
      this.params = []
      if (this.searchData.val && this.searchData.select) {
        if (this.searchData.val.indexOf(' ') > -1) {
          const arr = this.searchData.val.split(' ')
          arr.map(item => {
            if (item) {
              this.params.push({
                name: this.searchData.select,
                op: 'like',
                value: item
              })
            }
          })
        } else {
          this.params.push({
            name: this.searchData.select,
            op: 'like',
            value: this.searchData.val
          })
        }
      }
      this.page.pageNo = 1
      this.page.pageSize = 20
      this.getList()
    },
    handleSenior () {
      this.page.pageNo = 1
      this.page.pageSize = 20
      this.drawer = false
    },
    handleSelectionChange (selection) {
      // 勾选表格行
      this.tableSelected = selection
    },
    handleSortChange (val) {
      this.$set(this.sortSet, val.prop, val.order)
      this.sortCondition = []
      Object.keys(this.sortSet).forEach(key => {
        if (this.sortSet[key]) {
          this.sortCondition.push({
            asc: this.sortSet[key] === 'ascending',
            name: key
          })
        }
      })
      this.page.pageNo = 1
      this.page.pageSize = 20
      this.getList()
    },
    handleFile () {
      // 归档
      if (this.tableSelected.length < 1) {
        this.$message.warning('请至少勾选一条数据进行归档操作！')
        return
      }
      const ids = []
      this.tableSelected.map(item => {
        ids.push(item.id)
      })
      this.$confirm('是否对当前选择的档案进行归档？归档的数据会进入电子档案管理模块。', '文件归档', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        requestFile(this.idTable, ids).then(() => {
          this.$confirm('你选择的文件归档成功，请到【电子档案管理】模块进行档案查询', '归档成功', {
            confirmButtonText: '确定',
            cancelButtonText: '取消'
          }).then(() => {
            this.getList()
          }).catch(() => {
            this.getList()
          })
        }).catch(() => {
          this.$confirm('你选择的文件中存在未整理的档案，无法进行归档，请检查电子文件', '归档失败', {
            confirmButtonText: '确定',
            cancelButtonText: '取消' // 下载未整理信息
          }).then(() => {
          }).catch(() => {
            console.log('下载未整理信息')
          })
        })
      }).catch(() => {
      })
    },
    handleDel () {
      // 删除
      if (this.tableSelected.length > 0) {
        this.$confirm('此操作将永久删除该选中信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const ids = []
          this.tableSelected.map(item => {
            ids.push(item.id)
          })
          delArchivesList(this.idTable, ids).then(() => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getList()
          })
        }).catch(() => {
        })
      } else {
        this.$message.warning('请最少选择一条数据进行删除操作！')
      }
    },
    handlerRowDblClick (row) {
      // 双击编辑
      this.handleDrawer('edit', row)
    },
    handleDrawer (type, row) {
      const arr = [{
        title: '新增',
        size: '100%',
        direction: 'ltr',
        type: 'add'
      }, {
        title: ' 编辑',
        size: '100%',
        direction: 'ltr',
        type: 'edit'
      }, {
        title: '整理',
        size: '100%',
        direction: 'ltr',
        type: 'arrange'
      }, {
        title: '修改/替换',
        size: '500px',
        direction: 'rtl', // 右边拉出
        type: 'batchEdit'
      }, {
        title: '设置',
        size: '80%',
        direction: 'rtl', // 右边拉出
        type: 'set'
      }, {
        title: '高级检索',
        size: '50%',
        direction: 'rtl', // 右边拉出
        type: 'search'
      }]
      if (type === 'add') {
        this.rowData = this.tableSelected.length === 1 ? this.tableSelected[0] : {}
      }
      if (type === 'edit') {
        this.rowData = row
      }
      if (type === 'batchEdit' && this.tableSelected.length < 1) {
        this.$message.warning('请最少选择一条信息进行修改/替换操作！')
        return
      }
      if (type === 'arrange') {
        if (this.tableSelected.length === 1) {
          this.rowData = this.tableSelected[0]
          this.getPdfSrc(this.idTable, this.tableSelected[0].id)
        }
        if (this.tableSelected.length > 1) {
          this.$message.warning('只能选择一条数据进行整理！')
          return
        }
        if (this.tableSelected.length === 0) {
          this.$message.warning('请选择一条数据进行整理操作！')
          return
        }
      }

      this.drawer = true
      this.type = type
      arr.map(item => {
        if (item.type === type) {
          this.setDrawer = item
        }
      })
    },
    async handlePrev () {
      // 上一条
      if (this.page.pageNo === 1 && this.listIndex === 0) {
        this.$message.warning('已经没有上一条了！')
        return
      }
      if (this.page.pageNo > 1 && this.listIndex === 0) {
        this.page.pageNo = this.page.pageNo - 1
        await this.getList()
        this.rowData = this.tableData[this.tableData.length - 1]
        this.tableSelected = [this.tableData[this.tableData.length - 1]]
        this.getPdfSrc(this.idTable, this.rowData.id)
        return
      }
      this.rowData = this.tableData[this.listIndex - 1]
      this.tableSelected = [this.tableData[this.listIndex]]
      this.getPdfSrc(this.idTable, this.rowData.id)
    },
    async handleNext () {
      // 下一条
      if (this.page.pageNo === parseInt(this.listTable.total / this.page.pageSize) + 1 && this.listIndex === this.tableData.length - 1) {
        this.$message.warning('已经是最后一条了！')
        return
      }
      if (this.page.pageNo < (parseInt(this.listTable.total / this.page.pageSize) + 1) && this.listIndex === this.tableData.length - 1) {
        this.page.pageNo = this.page.pageNo + 1
        await this.getList()
        this.rowData = this.tableData[0]
        this.tableSelected = [this.tableData[0]]
        this.getPdfSrc(this.idTable, this.rowData.id)
        return
      }
      this.rowData = this.tableData[this.listIndex + 1]
      this.tableSelected = [this.tableData[this.listIndex]]
      this.getPdfSrc(this.idTable, this.rowData.id)
    },
    handleGetPdfSrc (val) {
      // 整理需要查看pdf原文
      this.getPdfSrc(val.idTable, val.id)
    },
    getPdfSrc (idTable, id) {
      getPdfOriginal(idTable, id).then(res => {
        // 请求pdf流文件后转vue-pdf预览用的src
        this.pdfSrc = getObjectURL(res.data)
      })
    },
    handleInOut (type) {
      // 导入、导出、报表
      const arr = ['导入', '导出', '报表']
      this.dialogVisible = true
      this.dialogTitle = arr[type]
      this.dialogWidth = arr[type] === '报表' ? '60%' : '80%'
      if (arr[type] === '报表') {
        requestRange(this.idTable).then(res => {
          this.reportScope = res.data.data
        })
      }
    },
    handlePreviewPrint (val) {
      // 预览并打印报表
      this.previewPrintLoading = true

      const param = {
        idTable: this.idTable,
        idCategory: this.idCategory,
        filters: val.dataScope === 'search' ? this.params : [] // this.searchParams.concat(this.params)
      }
      if (val.dataScope === 'select') {
        param.ids = []
        this.tableSelected.map(item => {
          param.ids.push(item.id)
        })
      } else {
        delete param.ids
      }
      requestPrint({ ...val, ...param }).then((res) => {
        // 请求pdf流文件后转vue-pdf预览用的src
        window.open(getObjectURL(res.data), '_blank')

        this.$message.success('生成成功！')
        this.previewPrintLoading = false
        this.dialogVisible = false
      }).catch(() => {
        this.previewPrintLoading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "../../../../../styles/mixin";

  .book {
    padding-top: 15px;

    .upload-demo {
      text-align: center;
    }

    .import-content {
      max-height: calc(90vh - 90px);
      overflow-y: auto;
    }

    ::v-deep .el-dialog__body {
      padding: 10px 20px;
    }

  }

</style>
